package com.cancer.common.util;

import java.util.LinkedList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

/*
 * @Description
 * @Author 李智海
 * @Date 2017年7月13日下午2:40:28
 */

public class SplitUtil {

	/**
	 * 将多个ID的String转化为一个List
	 * 
	 * @param queryIds
	 * @return
	 */
	public static List<Long> splitId(String queryIds) {
		List<Long> ids = new LinkedList<Long>();
		if (StringUtils.isNotBlank(queryIds)) {
			String[] splitIds = queryIds.split(",");
			if (splitIds != null && splitIds.length > 0) {
				for (int i = 0; i < splitIds.length; i++) {
					ids.add(Long.parseLong(splitIds[i]));
				}
			}
		}
		return ids;
	}
	
	/**
	 * 将多个Code的String转化为一个List
	 * 
	 * @param queryIds
	 * @return
	 */
	public static List<String> splitCode(String queryCodes) {
		List<String> codes = new LinkedList<String>();
		if (StringUtils.isNotBlank(queryCodes)) {
			String[] splitCodes = queryCodes.split(",");
			if (splitCodes != null && splitCodes.length > 0) {
				for (int i = 0; i < splitCodes.length; i++) {
					codes.add(splitCodes[i]);
				}
			}
		}
		return codes;
	}

	/**
	 * 将时间区间字符串转化为两个整数的数组
	 * 
	 * @param queryTime
	 * @return
	 */
	public static Long[] splitTime(String queryTime) {
		Long[] splitTimeLong = null;
		if (StringUtils.isNotBlank(queryTime)) {
			splitTimeLong = new Long[2];
			String[] splitTime = queryTime.split("-");
			for (int i = 0; i < splitTime.length; i++) {
				splitTimeLong[i] = Long.parseLong(splitTime[i]);
			}
		}
		return splitTimeLong;
	}
}
